<?php

namespace App\Service\Common;

use App\Params\Common\OrderListParams;
use App\Repository\MerchantsInfoRepo;
use App\Repository\SpecialOrderRepo;
use App\Service\BaseService;

class OrderService extends BaseService
{
    /**
     *  订单列表
     * @param OrderListParams $param
     * @return array
     */
    public function getOrderList(OrderListParams $param): array
    {
        $mid = (string)$param->getMid();
        if (empty($mid)) {
            return [
                'total' => 0,
                'list' => []
            ];
        }

        $merchantInfo = MerchantsInfoRepo::getInstance()->getInfoByAccessMid($param->getMid());

        if (empty($merchantInfo)) {
            return ['total' => 0,
                'list' => []];
        }

        $condition = $param->toArray();
        $condition['mer_id'] = $merchantInfo['merchants_id'];

        $query = SpecialOrderRepo::getInstance()->getOrderQuery($condition);

        return $this->toReturnList($query, $param->getPage(), $param->getPageSize());
    }
}
